<template>
  <div>
    <van-nav-bar :title="'新朋友'"></van-nav-bar>
    <div class="list">
      <div class="item" v-for="(item, index) in newFriend" :key="index">
        <img class="item-avatar" :src="item.avatar || avatar" :alt="item.nickName" />
        <div class="item-main">
          <div class="item-name">{{ item.nickname }}</div>
          <div class="gray">我是...</div>
        </div>
        <template v-if="item.is_read === 0">
          <span @click="agreeHandle(item)">同意</span>
          <span class="ml-10" @click="rejectHandle(item)">拒绝</span>
        </template>
        <template v-if="item.is_read === 1">
          <span class="ui-color-gray" v-if="item.status === 0">已同意</span>
          <span class="ui-color-gray" v-if="item.status === 1">已拒绝</span>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  computed: {
    newFriend() {
      return this.$store.state.ch.newFriend
    }
  },
  methods: {
    agreeHandle({ id }) {
      this.$store.dispatch('ch/dealFriendApply', { id, status: 0 })
    },
    rejectHandle({ id }) {
      this.$store.dispatch('ch/dealFriendApply', { id, status: 1 })
    }
  }
}
</script>

<style lang="less" scoped>
.view {
  background-color: #eee;
}

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  font-size: 12px;
  padding: 8px 10px;
  background-color: #fff;
}

.item-main {
  position: relative;
  flex: 1;
  &::after {
    position: absolute;
    bottom: -8px;
    content: " ";
    display: block;
    height: 1px;
    width: 100%;
    background: #eee;
    transform: scaleY(.5);
  }
}

.item-avatar {
  float: left;
  width: 36px;
  height: 36px;
  margin-right: 10px;
  border-radius: 4px;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.item-msg {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #666;
}

.gray {
  color: #b7b6b6;
  font-size: 12px;
}

.item-name {
  font-size: 13px;
  margin-bottom: 2px;
}
</style>
